package com.cskaoyan.javase.exception._1handle._4throw;

/**
 * @description: 空接口的作用
 * @author: wuguidong@cskaoyan.onaliyun.com
 **/

public class Demo3 {
    public static void main(String[] args) throws CloneNotSupportedException {
        /*System.out.println("before");
        try {
            judge(new A());
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        System.out.println("after");*/

        A a = new A();
        Object clone = a.clone();
    }

    //该方法用于判断传入的对象的类型是否实现了空接口
    public static void judge(Object o) throws CloneNotSupportedException {
        if (o instanceof Cloneable) System.out.println("正常克隆");
        else throw new CloneNotSupportedException("没有实现Cloneable接口,不允许克隆");
    }
}
interface Cloneable extends java.lang.Cloneable{}
class A implements Cloneable{
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}